package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
)

func main() {
	http.HandleFunc("/", HttpPostServer)
	http.ListenAndServe(":9091", nil)

}

//server获取http发的数据处理
func HttpPostServer(w http.ResponseWriter, r *http.Request) {
	defer r.Body.Close() //关闭
	//r.ParseForm()        //解析contentType := "application/x-www-form-urlencoded" //表单提交数据
	// fmt.Printf("ParseForm:%#v, name:%v, age:%v\n", r.ParseForm(), r.ParseForm().Get("name"), r.ParseForm().Get("age"))

	b, err := ioutil.ReadAll(r.Body) //contentType := "application/json" //解析json提交
	if err != nil {
		fmt.Printf("获取数据失败：%v\n", err)
		return
	}
	fmt.Printf("server获取数据：%v", string(b))
	answer := `{"status":"ok"}`
	w.Write([]byte(answer))
}
